/*
 * ScrollBar.hpp
 *
 *  Created on: 03-12-2010
 *      Author: Piotr
 */

#pragma once

#include "Container.hpp"
#include "Button.hpp"
#include "ArrowButton.hpp"
#include "utils/RangedValue.hpp"

class ScrollBar: public Container
{
	public:
		enum Alignment
		{
			HORIZONTAL, VERTICAL
		};

		static const float SIZE;

	private:
		RangedValue<int> range;
		Alignment alignment;

		Vector prevPoint;
		int singleHitChangeValue;

		ArrowButton* increaseButton;
		ArrowButton* decreaseButton;

	public:
		ScrollBar(Alignment alignment);

		float getScrolledPercent() const;
		Alignment getAlignment() const;
		void setBounds(const geometry::Rectangle& bounds);
		void setSize(const Dimension& size);

		virtual void draw(const ClipArea& clipArea);

	private:
		void setHorizontalComponentsPlacement();
		void setVerticalComponentsPlacement();

		float getScrollBarLength() const;
		float getThumbPosition() const;
		float getMoveDifference(const Vector& nextPoint) const;
		virtual void mousePressed(const MouseListener::EventArguments& arguments);
		virtual void mouseDragged(const MouseListener::EventArguments& arguments);
		virtual void mouseReleased(const MouseListener::EventArguments& arguments);
		void keyPressed(const KeyListener::EventArguments& arguments);
		void moveScrollbarHorizontallyWithKey(SDLKey key);
		void moveScrollbarVerticallyWithKey(SDLKey key);
};
